# -*- coding: utf-8 -*-
# @Time    : 2024/11/8  8:57
# @Author  : Nabby
# @FileName: dict_manage.py
# @Desc    :


from infrastructure.po.impl.dict_type_impl import DictTypeImpl
from infrastructure.po.impl.dict_data_impl import DictDataImpl
from infrastructure.utils.http import responser

class DictService(object):
    @classmethod
    def get_dict_type_list(cls, name=None, page=1, page_size=999):
        """
        查询字典类型列表
        :param status: 状态
        :param name: 查询
        :param page: 页码
        :param page_size: 每页数量
        :return:
        """
        response_data = []
        dict_type_list, total = DictTypeImpl.get_dict_type_list(name=name, page=page, page_size=page_size)
        for dict_type in dict_type_list:
            response_data.append(
                {
                    'dictTypeId': dict_type.id,
                    'dictTypeName': dict_type.name,
                }
            )
        return responser.send(10000, data={"total": total, "data": response_data})

    @classmethod
    def add_dict_type(cls, name, remark=None):
        dict_type_code = DictTypeImpl.add_dict_type(
            name=name,
            remark=remark
        )
        if dict_type_code:
            return responser.send(10000)
        else:
            return responser.send(10064)

    @classmethod
    def update_dict_type(cls, dict_type_id, name):
        dict_type_code = DictTypeImpl.update_dict_type(
            dict_type_id=dict_type_id,
            name=name,
        )
        if dict_type_code:
            return responser.send(10000)
        else:
            return responser.send(10065)

    @classmethod
    def delete_dict_type(cls, dict_type_id):
        dict_type_code = DictTypeImpl.delete_dict_type(dict_type_id=dict_type_id)
        if dict_type_code:
            return responser.send(10000)
        else:
            return responser.send(10033)

    @classmethod
    def get_dict_data_list(cls, dict_type_id, page=1, page_size=999):
        """
        查询字典数据列表
        :param status: 状态
        :param name: 查询
        :param page: 页码
        :param page_size: 每页数量
        :return:
        """
        response_data = []
        dict_data_list, total = DictDataImpl.get_dict_data_list(dict_type_id=dict_type_id, page=page, page_size=page_size)
        for dict_data in dict_data_list:
            response_data.append(
                {
                    'dictDataId': dict_data.id,
                    'dictLabel': dict_data.dict_label,
                    'dictValue': dict_data.dict_value,
                    'dictTypeId': dict_data.dict_type_id,
                    'dictSort': dict_data.dict_sort,
                    'status': dict_data.status,
                    'remark': dict_data.remark
                }
            )
        return responser.send(10000, data={"total": total, "data": response_data})

    @classmethod
    def add_dict_data(cls, dict_label, dict_value, dict_type_id, dict_sort, remark=None):
        dict_data_code = DictDataImpl.add_dict_data(
            dict_label=dict_label,
            dict_value=dict_value,
            dict_type_id=dict_type_id,
            dict_sort=dict_sort,
            remark=remark
        )
        if dict_data_code:
            return responser.send(10000)
        else:
            return responser.send(10065)

    @classmethod
    def update_dict_data(cls, dict_data_id, dict_label, dict_value, dict_type_id, dict_sort, remark=None):
        dict_data_code = DictDataImpl.update_dict_data(
            dict_data_id=dict_data_id,
            dict_label=dict_label,
            dict_value=dict_value,
            dict_type_id=dict_type_id,
            dict_sort=dict_sort,
            remark=remark
        )
        if dict_data_code:
            return responser.send(10000)
        else:
            return responser.send(10065)

    @classmethod
    def update_dict_data_status(cls, dict_data_id, status):
        DictDataImpl.change_dict_status(dict_data_id=dict_data_id, status=status)

        return responser.send(10000)

    @classmethod
    def delete_dict_data(cls, dict_data_id):
        DictDataImpl.delete_dict_data(dict_data_id=dict_data_id)
        return responser.send(10000)